package com.kerrykidz.system.util.sync;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class TableSyncMessage implements Serializable {

	private static final long serialVersionUID = 1L;

	public TableSyncMessage(List<SyncMessage> messages) {
		this.messages = messages;
	}

	/**
	 * 
	 * @Desc 获取批量插入sql
	 * @author QUINN
	 * @date 2014年9月18日下午6:34:20
	 * @return
	 */
	public SqlAndParam getBatchInsertSql() {
		List<Object> params = new ArrayList<Object>();
		SyncMessage firstMessage = this.messages.get(0);
		StringBuffer sql = new StringBuffer("INSERT INTO ");
		sql.append(firstMessage.getTableName()).append(" (");
		sql.append(firstMessage.getFlds(firstMessage.getDatas().keySet())).append(")VALUES");
		for (SyncMessage message : this.messages) {
			sql.append("(").append(firstMessage.getValues(message.getDatas().values())).append("),");
			params.add(message.getDatas().values());
		}
		sql.delete(sql.length() - 1, sql.length());
		return new SqlAndParam(sql.toString(), params.toArray());
	}

	private List<SyncMessage> messages;
	private SyncBean sync;

	public List<SyncMessage> getMessages() {
		return messages;
	}

	public SyncBean getSync() {
		return sync;
	}

}
